package com.peng.my_blog.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.peng.my_blog.api.entity.User;
import com.peng.my_blog.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author peng
 * @since 2018-09-25
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    @GetMapping("/makeSession")
    public void makeSession(HttpSession session){
        User user = new User();
        user.setId(666);
        user.setNickname("小埋鱼子酱");
        user.setFaceImg("666.png");
        session.setAttribute("user_info",user);
    }

    @HystrixCommand(fallbackMethod = "fallback")
    @RequestMapping(value = "/getUserInfoById",method = RequestMethod.GET)
    public User getUserInfoById(@RequestParam("id") Integer id){
        int i = 1 / 0;
        return userService.getById(id);
    }

    public User fallback(@RequestParam("id") Integer id) {
        System.out.println("触发article-fallback。。。");
        return new User();
    }

}
